﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Weazel.Math;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestConcat
  {
    [TestMethod]
    public void TestSimple32BitConcatenation()
    {
      Integer a = new Integer(16, 0x1111, false);
      Integer b = new Integer(16, 0x1111, false);
      Integer r = new Integer(32, false);
      Integer.Concat(ref r, a, b);

      Assert.AreEqual("11111111", r.ToHexadecimalString());
      Assert.AreEqual(32, r.Width);
    }

    [TestMethod]
    public void TestSimpleMultiUnitConcatenation()
    {
      Integer a = new Integer(32, 0x1111, false);
      Integer b = new Integer(32, 0x1111, false);
      Integer r = new Integer(64, false);
      Integer.Concat(ref r, a, b);

      Assert.AreEqual("111100001111", r.ToHexadecimalString());
      Assert.AreEqual(64, r.Width);
    }

    [TestMethod]
    public void TestComplexMultiUnitConcatenation()
    {
      Integer a = new Integer(29, 0x1111, false);
      Integer b = new Integer(11, 0x111, false);
      Integer r = new Integer(64, false);
      Integer.Concat(ref r, a, b);

      Assert.AreEqual("2220001111", r.ToHexadecimalString());
      Assert.AreEqual(64, r.Width);
    }

    [TestMethod]
    public void TestConcatenationWithVeryNarrowResult_1()
    {
      Integer a = new Integer(16, 0x1111, false);
      Integer b = new Integer(16, 0x1111, false);
      Integer r = new Integer(8, false);
      Integer.Concat(ref r, a, b);

      Assert.AreEqual("11", r.ToHexadecimalString());
      Assert.AreEqual(8, r.Width);
    }

    [TestMethod]
    public void TestConcatenationWithNarrowResult_2()
    {
      Integer a = new Integer(64, 0x1111111122222222 , false);
      Integer b = new Integer(32, 0x33333333, false);
      Integer r = new Integer(40, false);

      Integer.Concat(ref r, b, a);

      Assert.AreEqual("2233333333", r.ToHexadecimalString());
      Assert.AreEqual(40, r.Width);
    }
  }
}
